<%--
  ** Copyright(c) 2005 BroadVision, Inc. All rights reserved.
  **
  ** This software is copyrighted.  Under the copyright laws, this software
  ** may not be copied, in whole or in part, without prior written consent
  ** of BroadVision, Inc. or its assignees. This software is provided under
  ** the terms of a license between BroadVision and the recipient, and its
  ** use is subject to the terms of that license.
  **
  ** This software may be protected by one or more U.S. and International
  ** patents. Certain applications of BroadVision One-To-One software are
  ** covered by U.S. patent 5,710,887.
  **
  ** TRADEMARKS: BroadVision and the BroadVision logo are registered
  ** trademarks, and BroadVision One-To-One is a trademark of BroadVision,
  ** Inc. IONA and Orbix are trademarks of IONA Technologies, Ltd. RSA,
  ** MD5, and RC2 are trademarks of RSA Data Security, Inc. All other
  ** trademarks, service marks, and trade names belong to their respective
  ** owners. BroadVision, Inc. disclaims any proprietary interest in the
  ** marks and names of others.
  --%>

<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>

<%@ page import="com.broadvision.report.admin.JDBCResourceConfig" %>

<%@include file="/bp/report/runtimeReportConfigPreamble.jsp" %>

  <!-- ========================================================
    ** JDBC resources
    -->
  <script language="Javascript">
  function deleteJdbc(url)
  {
    var msg = '<bean-el:message key="bp.report.resource.confirm.delete" bundle="bp.messages"/>';

    if (!confirm(msg))
      return false;

    location.replace(url);
    return true;
  }

  function createJdbc(form)
  {
    // TODO: check if name is already used

    return validateReportResourceForm(form);
  }
  </script>
  <tr>
    <td valign="top" colspan="2">
      <div class="pageSubtitle">
        <span class="left">
          <bean-el:message
            key="bp.report.runtimeReportConfig.jdbc.subtitle"
            bundle="bp.messages"
          />
        </span>
        <span class="right">&nbsp;</span>
      </div>

      <table class="dataTable" summary="runtime report jdbc resource table"
             border="0" cellspacing="1" cellpadding="2" width="100%">
        <tr class="listHeader">
          <th id="Name:JDBC" align="left">
            <bean-el:message
              key="bp.report.runtimeReportConfig.jdbc.header.name"
              bundle="bp.messages"
            />
          </th>
          <th id="Type:JDBC" align="left">
            <bean-el:message
              key="bp.report.runtimeReportConfig.jdbc.header.type"
              bundle="bp.messages"
            />
          </th>
          <th id="Location:JDBC" align="left">
            <bean-el:message
              key="bp.report.runtimeReportConfig.jdbc.header.location"
              bundle="bp.messages"
            />
          </th>
          <th id="Actions:JDBC" align="left" nowrap>
            <bean-el:message key="header.actions" bundle="bp.messages"/>
          </th>
        </tr>

        <% pageContext.setAttribute("jdbcList", model.getResourceList()); %>
        <c:forEach var="jdbc" items="${jdbcList}" varStatus="index">
          <%
          final JDBCResourceConfig jdbc =
                  (JDBCResourceConfig)pageContext.getAttribute("jdbc");
          String jdbcType;
          if (jdbc.getConnectionInfo().isThroughJndi()) {
              pageContext.setAttribute(
                          "jdbcType",
                          "bp.report.runtimeReportConfig.jdbc.type.datasource");
              pageContext.setAttribute("jdbcLoc", jdbc.getJndi());
          }
          else {
              pageContext.setAttribute(
                          "jdbcType",
                          "bp.report.runtimeReportConfig.jdbc.type.driver");
              pageContext.setAttribute("jdbcLoc", jdbc.getUrl());
          }
          %>
          <tr class="<c:out value="${listEvenOrOdd[(index.count+1)%2]}"/>">
            <td headers="Name:JDBC">
              <c:url var="viewUrl" value="/bp/reportResourceView.do">
                <c:param name="name" value="${jdbc.name}"/>
              </c:url>
              <a href="<c:out value="${viewUrl}"/>">
                <c:out value="${jdbc.name}"/>
              </a>
            </td>
            <td headers="Type:JDBC">
              <bean-el:message key="${jdbcType}" bundle="bp.messages"/>
            </td>
            <td headers="Location:JDBC"><c:out value="${jdbcLoc}"/></td>
            <td nowrap align="left" headers="Actions:JDBC">
              <c:url var="editUrl" value="/bp/reportResourceEdit.do">
                <c:param name="name" value="${jdbc.name}"/>
                <c:param name="command" value="edit"/>
              </c:url>
              <a href="<c:out value="${editUrl}"/>">
                <c:out value="${editImg}" escapeXml="false"/>
              </a>

              <c:url var="delUrl" value="/bp/reportResourceDelete.do">
                <c:param name="name" value="${jdbc.name}"/>
              </c:url>
              <a href="#" onclick="deleteJdbc('<c:out value="${delUrl}"/>')">
                <c:out value="${deleteImg}" escapeXml="false"/>
              </a>
            </td>
          </tr>
        </c:forEach>

        <html-el:javascript formName="reportResourceForm"/>
        <html-el:form action="/bp/reportResourceAdd.do"
                      onsubmit="return createJdbc(this);">
          <html-el:hidden
            name ="reportResourceForm" property="command" value="add"
          />
          <tr>
            <td headers="Name:JDBC" align="left">
              <html-el:text
                name ="reportResourceForm" property="name" value=""
              />
            </td>
            <td headers="Type:JDBC" align="left">
              <html-el:select property="type">
                <html-el:option
                    key="bp.report.runtimeReportConfig.jdbc.type.driver"
                    bundle="bp.messages"
                    value="jdbc.driver"
                />
                <html-el:option
                    key="bp.report.runtimeReportConfig.jdbc.type.datasource"
                    bundle="bp.messages"
                    value="jdbc.datasource"
                />
              </html-el:select>
            </td>
            <td headers="Location:JDBC" align="left">&nbsp;</td>
            <td headers="Actions:JDBC" align="left" nowrap>
              <html-el:submit styleClass="inputButton" property="submitBtn">
                <bean-el:message key="button.add" bundle="bp.messages"/>
              </html-el:submit>
            </td>
          </tr>
        </html-el:form>
      </table>
    </td>
  </tr>

<%@include file="/bp/report/runtimeReportConfigPostamble.jsp" %>

<!-- =============================================================
  ** vim: set ts=2 expandtab syntax=jsp:
  -->
